﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.StartupTasks;
using System.Text;
using System.Threading.Tasks;
using Autofac;

namespace System
{
    public class EngineContext
    {
        public static void Initialize()
        {
            RunStartupTasks();
            InitializeContainer();
        }

        private static void RunStartupTasks()
        {
            var assemblies = AppDomain.CurrentDomain.GetAssemblies();
            var startUpTasks = assemblies.GetInstancesOfTypesImplementing<IStartupTask>().OrderBy(x => x.Order);
            foreach (var startUpTask in startUpTasks)
            {
                startUpTask.Execute();
            }
        }
        private static void InitializeContainer()
        {
           // var builder = new ContainerBuilder();
            ContainerManager.Current.Configure();
        }

        //public static IEngine Current
                //{
                //    get
                //    {
                //        if (Singleton<IEngine>.Instance == null)
                //        {
                //            Initialize(false);
                //        }
                //        return Singleton<IEngine>.Instance;
                //    }
                //}
            }
}
